package cn.panda.edu.controller;

import cn.panda.edu.model.Select;
import cn.panda.edu.service.SelectService;
import cn.panda.edu.util.ResultDataUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * 类描述：  对选择题的CURD操作
 * @author: 张春雷
 * @date： 2018-01-18 上午11:01:28
 */
@RestController
@RequestMapping(value="/api/teacher/courseware")
public class TeacherSelectController {
	
	@Autowired
	private SelectService selectService;
	
	@ApiOperation(value="通过ID获取选择题" , notes="")
	@ApiImplicitParam(name = "selectId", value = "选择题ID", required = true, dataType = "Integer")
	@RequestMapping(value = "/select", method = RequestMethod.POST)
	public Object selectByPrimaryKey(Integer selectId) {
		Select select = selectService.selectByPrimaryKey(5);
		return ResultDataUtil.resData(200, "", select);
	}
	
	@ApiOperation(value="动态更新选择题" , notes="")
    @ApiImplicitParam(name = "record", value = "选择题对象", required = true, dataType = "Select")
	@RequestMapping(value = "/select/update", method = RequestMethod.POST)
	public Object updateByPrimaryKeySelective(Select record) {
		int status=200;
		String message=null;
		try {
			selectService.updateByPrimaryKeySelective(record);
			status=200;
			message="更新成功!";
		} catch (Exception e) {
			status=500;
			message="更新失败!";
		}
		return ResultDataUtil.resData(status, message, null);
	}
	
	@ApiOperation(value="根据ID删除选择题" , notes="")
    @ApiImplicitParam(name = "selectId", value = "选择题ID", required = true, dataType = "Integer")
	@RequestMapping(value = "/select/delete", method = RequestMethod.POST)
	public  Object deleteByPrimaryKey(Integer selectId) {
		int status=200;
		String message=null;
		try {
			selectService.deleteByPrimaryKey(selectId);
			status=200;
			message="删除成功!";
		} catch (Exception e) {
			status=500;
			message= "删除失败!";
		}
		return ResultDataUtil.resData(status, message, null);
	}
	
	@ApiOperation(value="动态添加选择题" , notes="")
    @ApiImplicitParam(name = "record", value = "选择题对象", required = true, dataType = "Select")
	@RequestMapping(value = "/select/insert", method = RequestMethod.POST)
	public  Object insertSelective(Select record) {
		int status=200;
		String message=null;
		try {
			selectService.insertSelective(record);
			status=200;
			message="添加成功!";
		} catch (Exception e) {
			status= 500;
			message="添加失败!";
		}
		return ResultDataUtil.resData(status, message, null);
	}
}
